package com.bk.bookviews.enums;


import com.bk.bookviews.util.StringUtil;

/**
 * 响应错误码&错误信息
 */
public enum MsgEnum {
	
	/**
	 * 请求成功
	 */
	SUCCESS("000000",""),
	
	/**
	 * HTTP请求失败
	 */
	HTTP_FAILED("httperror","HTTP请求失败"),
	
	/**
	 * 请求失败
	 */
	FAILED("999999","请求失败"),
	
	/**
	 * 未知
	 */
    UNKNOWN("BP1427","未知"),
    
    /**
     * 微服务间调用异常
     */
    SERVICE_ERROR("120006","微服务间调用异常"),
    
    CUST_INFO_NULL("000001","未查询到账户信息，请先开户！"),
    ;
	
	private String code;

	private String msg;
	
	private MsgEnum(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	/**
	 * 根据错误码得到错误信息
	 * @param code
	 * @return
	 */
	public static String getByCode(String code){
    	for(MsgEnum msgEnum:MsgEnum.values()){
    		if(msgEnum.getCode().equals(code)){
    			return msgEnum.getMsg();
    		}
    	}
    	return null;
    }
	
	/**
	 * 枚举中是否含有传来的code
	 * @param code
	 * @return
	 */
	public static boolean hasCode(String code){
		if(StringUtil.isBlank(code) || getByCode(code) == null){
			return false;
		}
		return true;	
	}
}
